home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / AX25.H < prev    next >
Text File  |  1993-11-21  |  10KB  |  290 lines

  1. #ifndef    _AX25_H
  2. #define    _AX25_H
  3.  
  4. #ifndef    _GLOBAL_H
  5. #include "global.h"
  6. #endif
  7.  
  8. #ifndef    _MBUF_H
  9. #include "mbuf.h"
  10. #endif
  11.  
  12. #ifndef _TIMER_H
  13. #include "timer.h"
  14. #endif
  15.  
  16. #ifndef    _IFACE_H
  17. #include "iface.h"
  18. #endif
  19.  
  20. #ifndef _SOCKET_H
  21. #include "socket.h"
  22. #endif
  23.  
  24. /* AX.25 datagram (address) sub-layer definitions */
  25.  
  26. #define AXROUTESIZE     499
  27. #define AXROUTEHOLDTIME    (30 * DAYS)
  28.  
  29. extern int32 Axholdtime;
  30.  
  31. #define    MAXDIGIS    7        /* Maximum number of digipeaters */
  32. #define    ALEN        6        /* Number of chars in callsign field */
  33. #define    AXALEN        7        /* Total AX.25 address length, including SSID */
  34. #define    AXBUF        10        /* Buffer size for maximum-length ascii call */
  35.  
  36. /* Bits within SSID field of AX.25 address */
  37. #define    SSID        0x1e    /* Sub station ID */
  38. #define DAMA        0x20    /* DAMA bke 920531   DAMA-Master ID */
  39. #define    REPEATED    0x80    /* Has-been-repeated bit in repeater field */
  40. #define    E            0x01    /* Address extension bit */
  41. #define    C            0x80    /* Command/response designation */
  42.  
  43. /* Upper sub-layer (LAPB) definitions */
  44. /* Control field templates */
  45. #define    I        0x00        /* Information frames */
  46. #define    S        0x01        /* Supervisory frames */
  47. #define    RR        0x01        /* Receiver ready */
  48. #define    RNR        0x05        /* Receiver not ready */
  49. #define    REJ        0x09        /* Reject */
  50. #define    U        0x03        /* Unnumbered frames */
  51. #define    SABM    0x2f        /* Set Asynchronous Balanced Mode */
  52. #define    DISC    0x43        /* Disconnect */
  53. #define    DM        0x0f        /* Disconnected mode */
  54. #define    UA        0x63        /* Unnumbered acknowledge */
  55. #define    FRMR    0x87        /* Frame reject */
  56. #define    UI        0x03        /* Unnumbered information */
  57. #define    PF        0x10        /* Poll/final bit */
  58.  
  59. #define    MMASK    7            /* Mask for modulo-8 sequence numbers */
  60.  
  61. /* FRMR reason bits */
  62. #define    W        1            /* Invalid control field */
  63. #define    X        2            /* Unallowed I-field */
  64. #define    Y        4            /* Too-long I-field */
  65. #define    Z        8            /* Invalid sequence number */
  66.  
  67. /* AX25 protocol constants */
  68. #define DST_C   1           /* Set C bit in dest addr */
  69. #define SRC_C   2           /* Set C bit in source addr */
  70. #define VERS1   0           /* AX25L2V1 compatible frame */
  71. #define CMD     (DST_C)     /* Command frame */
  72. #define POLL    (DST_C|PF)  /* Poll frame */
  73. #define RESP    (SRC_C)     /* Response frame */
  74. #define FINAL   (SRC_C|PF)    /* Final frame */
  75.  
  76. /* Round trip timing parameters */
  77. #define AGAIN   8               /* Average RTT gain = 1/8 */
  78. #define DGAIN   4               /* Mean deviation gain = 1/4 */
  79.  
  80. extern struct iface *axroute_default_ifp;
  81.  
  82. extern char Mycall[AXALEN], Ax25multi[][AXALEN], *Ax25states[],
  83.             *Ax25reasons[], Nomycall[];
  84.  
  85. extern int T3disc;
  86.  
  87. extern int16 Digipeat,T1init,T2init,T3init,T4init,T5init,Retries,
  88.              Maxframe,Paclen,Pthresh,Axwindow;
  89.  
  90. /* Internal representation of an AX.25 address */
  91. struct ax25_addr {
  92.     char call[ALEN];
  93.     char ssid;
  94. };
  95. #define NULLAXADDR (struct ax25_addr *)0
  96.  
  97. struct axroute_tab {
  98.     struct ax25_addr call;
  99.     struct axroute_tab *digi;
  100.     struct iface *ifp;
  101.     int perm;
  102.     int32 time;
  103.     struct axroute_tab *next;
  104. };
  105.  
  106. extern struct axroute_tab *Axroute_tab;
  107.  
  108. struct ax_saverecord {
  109.     struct ax25_addr call;
  110.     struct ax25_addr digi;
  111.     short dev;
  112.     int32 time;
  113. };
  114.  
  115. /* Internal representation of an AX.25 header */
  116. struct ax25 {
  117.     struct ax25_addr dest;                /* Destination address */
  118.     struct ax25_addr source;            /* Source address */
  119.     struct ax25_addr digis[MAXDIGIS];    /* Digi string */
  120.     int ndigis;                            /* Number of digipeaters */
  121.     int cmdrsp;                            /* Command/response */
  122. };
  123.  
  124. /* Per-connection link control block
  125.  * These are created and destroyed dynamically,
  126.  * and are indexed through a hash table.
  127.  * One exists for each logical AX.25 Level 2 connection
  128.  */
  129. struct ax25_cb {
  130.     struct ax25_cb *next;        /* linked list pointers */
  131.  
  132.     char path[70];
  133.     int pathlen;
  134.  
  135.     struct iface *iface;        /* Interface */
  136.  
  137.     struct mbuf *txq;            /* Transmit queue */
  138.     struct mbuf *rxasm;            /* Receive reassembly buffer */
  139.     struct mbuf *rxq;            /* Receive queue */
  140.     int16 rcvcnt;
  141.     int32 sndqtime;
  142.  
  143.     struct axreseq {            /* Resequencing queue */
  144.         struct mbuf *bp;
  145.         int sum;
  146.     } reseq[8];
  147.  
  148.     char rejsent;                /* REJ frame has been sent */
  149.     char rnrsent;               /* RNR frame has been sent */
  150.     char polling;                /* Poll frame has been sent */
  151.     char clone;                    /* Server-type cb, will be cloned */
  152.     int32 remotebusy;            /* Remote sent RNR */
  153.  
  154.     char reason;                /* Reason for connection closing */
  155. #define    LB_NORMAL            0    /* Normal close */
  156. #define    LB_DM                1    /* Received DM from other end */
  157. #define    LB_TIMEOUT            2    /* Excessive retries */
  158. #define LB_UNUSED            3    /* Link is redundant - unused */
  159.     int mode;
  160. #define STREAM                0
  161. #define DGRAM                1
  162.     char vs;                    /* Our send state variable */
  163.     char vr;                    /* Our receive state variable */
  164.     char unack;                    /* Number of unacked frames */
  165.     int closed;                    /* disc when sendqueue empty */
  166.     int cwind;                    /* Congestion window */
  167.     unsigned retries;            /* Retry counter */
  168.     int state;                    /* Link state */
  169. #define    DISCONNECTED        1
  170. #define LISTEN                2
  171. #define    CONNECTING            3
  172. #define    DISCONNECTING        4
  173. #define    CONNECTED            5
  174. #define TIMEWAIT            6
  175.     struct timer t1;            /* Retransmission timer */
  176.     struct timer t2;            /* Acknowledgement delay timer */
  177.     struct timer t3;            /* Keep-alive poll timer */
  178.     struct timer t4;            /* Link redundancy timer */
  179.     struct timer t5;            /* Packet assembly timer */
  180.     int32 srt;                    /* Smoothed round-trip time, ms */
  181.     int32 mdev;                    /* Mean rtt deviation, ms */
  182.     int32 sndtime[8];            /* time of 1st transmission */
  183.  
  184.     void (*r_upcall) __ARGS((struct ax25_cb *,int));     /* Receiver upcall */
  185.     void (*t_upcall) __ARGS((struct ax25_cb *,int));     /* Transmit upcall */
  186.     void (*s_upcall) __ARGS((struct ax25_cb *,int,int)); /* State change upcall */
  187.  
  188.     int user;                    /* User pointer */
  189.     int segremain;                /* Segmenter state */
  190.     struct mbuf *segasm;        /* Segmenter reassembly buffer */
  191.     struct ax25_cb *peer;       /* Pointer to peer's control block */
  192.     int dama;                   /* DAMA bke 920609   DAMA-Flag */
  193. };
  194. #define    NULLAX25    ((struct ax25_cb *)0)
  195.  
  196. extern struct ax25_cb Ax25default,*Ax25_cb;
  197.  
  198. /* C-bit stuff */
  199. #define    LAPB_UNKNOWN    0
  200. #define    LAPB_COMMAND    1
  201. #define    LAPB_RESPONSE    2
  202.  
  203. /* AX.25 Level 3 Protocol IDs (PIDs) */
  204. #define PID_X25            0x01    /* CCITT X.25 PLP */
  205. #define    PID_SEGMENT        0x08    /* Segmentation fragment */
  206. #define PID_TEXNET        0xc3    /* TEXNET datagram protocol */
  207. #define    PID_LQ            0xc4    /* Link quality protocol */
  208. #define    PID_IP            0xcc    /* ARPA Internet Protocol */
  209. #define    PID_ARP            0xcd    /* ARPA Address Resolution Protocol */
  210. #define PID_FLEXNET        0xce    /* Flexnet routing info */
  211. #define    PID_NETROM        0xcf    /* NET/ROM */
  212. #define    PID_NO_L3        0xf0    /* No level 3 protocol */
  213.  
  214. #define    SEG_FIRST        0x80    /* First segment of a sequence */
  215. #define    SEG_REM            0x7f    /* Mask for # segments remaining */
  216.  
  217. #define    AX_EOL            "\r"    /* AX.25 end-of-line convention */
  218.  
  219. /* Link quality database record format
  220.  * Currently used only by AX.25 interfaces
  221.  */
  222. struct lq {
  223.     char addr[AXALEN];        /* Hardware address of station heard */
  224.     int32 time;                /* Time station was last heard */
  225.     int32 currxcnt;            /* Current # of packets heard from this station */
  226.     unsigned char pid;
  227.     unsigned char lock;
  228. };
  229. #define    NULLLQ    (struct lq *)0
  230.  
  231. /* Max number of fake AX.25 interfaces for RFC-1226 encapsulation */
  232. #define NAX25   10
  233.  
  234. /* Codes for the open_ax25 call */
  235. #define    AX_PASSIVE    0
  236. #define    AX_ACTIVE    1
  237. #define    AX_SERVER    2    /* Passive, clone on opening */
  238.  
  239. void ax_recv __ARGS((struct iface *,struct mbuf *));
  240. void axip_input __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,int rxbroadcast));
  241. int axip_raw __ARGS((struct iface *iface,struct mbuf *bp));
  242. int ax_send __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,int prec,
  243.     int del,int tput,int rel));
  244. int ax_output __ARGS((struct iface *iface,char *dest,char *source,int16 pid,
  245.     struct mbuf *data));
  246. struct axroute_tab *axroute_tabptr __ARGS((struct ax25_addr *call,int create));
  247. void axroute_add __ARGS((struct ax25_cb *cp,int perm));
  248. int is_bud __ARGS((char *call,int store));
  249. int axflush __ARGS((struct iface *ifp));
  250. int maxheard __ARGS((struct iface *ifp,int num));
  251. /* int ax25val __ARGS((struct ax25_cb *axp));    */
  252. int disc_ax25 __ARGS((struct ax25_cb *axp));
  253. int kick_ax25 __ARGS((struct ax25_cb *axp));
  254. struct ax25_cb *open_ax25 __ARGS((struct iface *,char *,char *,int,
  255.     void (*) __ARGS((struct ax25_cb *,int)),
  256.     void (*) __ARGS((struct ax25_cb *,int)),
  257.     void (*) __ARGS((struct ax25_cb *,int,int)),int user));
  258. struct mbuf *recv_ax25 __ARGS((struct ax25_cb *axp,int16 cnt));
  259. int reset_ax25 __ARGS((struct ax25_cb *axp));
  260. int send_ax25 __ARGS((struct ax25_cb *axp,struct mbuf *bp,int pid));
  261. int addreq __ARGS((char *a,char *b));
  262. void addrcp __ARGS((char *to,char *from));
  263. struct ax25_cb *find_ax25 __ARGS((char *,char *));
  264. void del_ax25 __ARGS((struct ax25_cb *axp));
  265. char *pax25 __ARGS((char *e,char *addr));
  266. int setcall __ARGS((char *out,char *call));
  267. int  sendctl __ARGS((struct ax25_cb *axp,int cmdrsp,int cmd));
  268. int t1_timeout __ARGS((struct ax25_cb *cp));    /* ax25val */
  269. void t2_timeout __ARGS((struct ax25_cb *cp));
  270. void t3_timeout __ARGS((struct ax25_cb *cp));
  271. void t4_timeout __ARGS((struct ax25_cb *cp));
  272. void t5_timeout __ARGS((struct ax25_cb *cp));
  273. struct mbuf *segmenter __ARGS((struct mbuf *bp,int16 ssize));
  274. void init_maxheard __ARGS((struct iface *ifp));
  275. void build_path __ARGS((struct ax25_cb *axp,struct iface *ifp,char *newpath,int flags));
  276.  
  277. /* definition for flags */
  278. #define REVERSE        0x01
  279. #define NEWSRT        0x02
  280.  
  281. int st_ax25 __ARGS((struct ax25_cb *cp));        /* ax25val */
  282. int callreq __ARGS((char *a));
  283.  
  284. /* In socket.c: */
  285. void s_arcall __ARGS((struct ax25_cb *axp,int cnt));
  286. void s_ascall __ARGS((struct ax25_cb *axp,int old,int new));
  287. void s_atcall __ARGS((struct ax25_cb *axp,int cnt));
  288.  
  289. #endif    /* _AX25_H */
  290.